package 力扣日常刷题.木22一月.第18天0130;

/**
 * @author 帅小伙
 * @date 2022/1/30
 * @description 找target的右边界 和  target - 1 的边界
 */
public class Demo42JZ数组中重复的数字 {


    public int search(int[] nums, int target) {
        return helper(nums, target) - helper(nums, target - 1);
    }

    int helper(int[] nums, int tar) {
        int i = 0, j = nums.length - 1;
        while (i <= j) {
            int m = (i + j) / 2;
            if(nums[m] <= tar) i = m + 1;
            else j = m - 1;
        }
        return i;
    }


}
